function
<system_error>

std::operator<<

template <class charT, class traits>  basic_ostream<charT,traits>& operator<< ( basic_ostream<charT,traits>& os,                                             const error_code& ec );
Insert into ostream
Writes a textual representation of the error code, producing the same output as the following operation:
1
os << ec.category.name() << ':' << ec.value()

Parameters

os
ostream object.
ec
error_code object.

Return value

The same as parameter os.

If some error happens during the output operation, the stream's badbit flag is set, and if the appropriate flag has been set with ios::exceptions, an exception is thrown.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// error_code::operator<<
#include <iostream>       // std::cout, std::ios
#include <system_error>   // std::system_error
#include <fstream>        // std::ifstream

int main()
{
  std::ifstream is;
  is.exceptions (std::ios::failbit);
  try {
    is.open ("unexistent.txt");
  } catch (const std::system_error& e) {
    std::cout << "Exception caught:\n";
    std::cout << e.code() << " = " << e.what() << '\n';
  }
}

Possible output:
Exception caught:
iostream:1 = ios_base::failbit set


See also